package com.scorpio.scbasics.rediostation.service.impl;


import com.scorpio.common.annotation.DataSource;
import com.scorpio.common.core.domain.Result;
import com.scorpio.common.enums.DataSourceType;
import com.scorpio.common.service.impl.BaseServiceImpl;
import com.scorpio.common.utils.StringUtils;
import com.scorpio.common.utils.bean.BeanUtils;
import com.scorpio.scbasics.rediostation.domain.BizBannerEntity;
import com.scorpio.scbasics.rediostation.dto.BizBannerDTO;
import com.scorpio.scbasics.rediostation.mapper.BizBannerMapper;
import com.scorpio.scbasics.rediostation.service.IBizBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author scorpio
 * @date 2020-10-14
 */
@Service
@DataSource(DataSourceType.SLAVE)
public class BizBannerServiceImpl extends BaseServiceImpl<BizBannerMapper, BizBannerEntity> implements IBizBannerService {


    @Autowired
    private BizBannerMapper bizBannerMapper;

    @Override
    public Result queryBanner() {
        List<BizBannerEntity> bizBannerEntities = bizBannerMapper.queryBanner();
        List list = new ArrayList<>(bizBannerEntities.size());
        for (BizBannerEntity bizBannerEntity : bizBannerEntities) {
            BizBannerDTO bizBannerDTO = new BizBannerDTO();
            BeanUtils.copyBeanProp(bizBannerDTO, bizBannerEntity);
            if (StringUtils.isNotBlank(bizBannerEntity.getText())) {
                bizBannerDTO.setText(String.valueOf(Base64.getEncoder().encode(bizBannerEntity.getText().getBytes())));
            }
            bizBannerDTO.setBanner_img(bizBannerEntity.getBannerImg());
            bizBannerDTO.setCreate_time(bizBannerEntity.getCreateTime());
            bizBannerDTO.setIs_valid(bizBannerEntity.getIsValid());
            bizBannerDTO.setOperator_id(bizBannerEntity.getOperatorId());
            bizBannerDTO.setLastupdate_time(bizBannerEntity.getLastupdateTime());
            list.add(bizBannerDTO);
        }
        HashMap hashMap = new HashMap();
        hashMap.put("list", list);
        return Result.success(hashMap);
    }
}
